package com.mmall.common;

import com.google.common.collect.Sets;

import java.util.Set;

/**
 * 常量声明接口
 * Created by qezhhnjy on 2017/9/22-16:44.
 */
public interface IConst {

    String CURRENT_USER = "currentUser";

    String USERNAME = "username";

    String EMAIL = "email";

    String TELEPHONE = "telephone";

    //用户权限
    interface Role {
        int ADMIN = 1;
        int CUSTOMER = 0;
    }

    //购物车常量
    interface CartConst {
        //指定购物车是否被勾选
        int CHECKED = 1;
        int UN_CHECKED = 0;

        //商品可购买限制成功与否
        //库存不足
        String LIMIT_NUM_FAIL = "limit num fail";
        //库存足够
        String LIMIT_NUM_SUCCESS = "limit num success";
    }

    //排序语句判定
    interface OrderBy {
        //价格排序集合
        Set<String> PRICE_ORDER = Sets.newHashSet("price desc", "price asc");
    }

    //商品销售状态
    enum ProductStatus {

        ON_SALE("在售", 1);

        public final String value;
        public final int CODE;

        ProductStatus(String value, int code) {
            this.value = value;
            this.CODE = code;
        }

    }

    //订单状态,这里code大小也应该按照业务的真实逻辑排序.
    //这样可以使用>/<来处理一些多个状态同时选择的情况.
    enum OrderStatus {

        CANCELED(0, "已取消"),
        NO_PAY(10, "未付款"),
        PAID(20, "已付款"),
        SHIPPED(40, "已发货"),
        ORDER_SUCCESS(50, "交易成功"),
        ORDER_CLODE(60, "交易关闭");

        OrderStatus(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public final String value;
        public final int code;

        public static String getValue(int code) {
            for (OrderStatus orderStatus : values()) {
                if (orderStatus.code == code)
                    return orderStatus.value;
            }
            throw new RuntimeException("没有该支付状态!");
        }
    }

    //交易状态常量
    //支付宝有四种交易状态:WAIT_BUYER_PAY 等待付款/TRADE_CLOSED 交易超时关闭或支付完成后全额退款.
    //TRADE_SUCCESS 交易支付成功/TRADE_FINISHED 交易结束,不可退款.
    interface AlipayCallback {

        String TRADE_STATUS_WAIT_BUYER_PAY = "WAIT_BUYER_PAY";
        String TRADE_STATUS_TRADE_SUCCESS = "TRADE_SUCCESS";

        String RESPONSE_SUCCESS = "success";
        String RESPONSE_FAILED = "failed";
    }

    //支付平台信息
    enum Platform {

        ALIPAY(1, "支付宝"),
        WECHAT(2, "微信");

        Platform(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public final String value;
        public final int code;
    }

    //支付类型,在线支付...
    enum PaymentType {

        ONLINE(1, "在线支付");

        PaymentType(int code, String value) {
            this.code = code;
            this.value = value;
        }

        public final String value;
        public final int code;

        public static String getValue(int code) {
            for (PaymentType paymentType : values()) {
                if (paymentType.code == code)
                    return paymentType.value;
            }
            throw new RuntimeException("没有找到对应的支付类型!");
        }
    }

}
